import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/pages/model/bean.dart';
import 'package:flutter_massage/pages/technician/technician_detail/technician_detail_page.dart';
import 'package:flutter_massage/service/get_storage_service.dart';
import 'package:get/get.dart';

class MyAttentionLogic extends GetxController {
  static const String keyListener = 'key_listener_refresh_my_attention_page';

  List<TechnicianBean> list = [];

  @override
  void onReady() {
    super.onReady();
    getData();

    CommonObservable().addObserver(keyListener, refreshPage);
    CommonObservable().addObserver(TechnicianDetailPage.keyListener, refreshPage);
  }

  @override
  void onClose() {
    super.onClose();
    CommonObservable().removeObserver(keyListener, refreshPage);
    CommonObservable().removeObserver(TechnicianDetailPage.keyListener, refreshPage);
  }

  void getData() {
    list = GetStorageService.getAttentionTechnicianList();
    List blackList = GetStorageService.blackList();
    for (var value in blackList) {
      list.removeWhere((element) => element.id == value);
    }
    update();
  }

  void refreshPage(key, [value]) => getData();
}
